package com.itheima.stock.controller;

import cn.hutool.http.HttpResponse;
import com.itheima.stock.pojo.domain.*;
import com.itheima.stock.pojo.entity.StockRtInfo;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * 股票相关接口
 */
@RequestMapping("/api/quot")
@RestController
public class StockController {
    @Autowired
    private StockService stockService;

    /**
     * 获取国内大盘最新的数据
     * @return
     */
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfo(){
        return stockService.getInnerMarketInfo();
    }

    /**
     * 获取外盘指数行情数据
     */
    @GetMapping("/external/index")
    public R<List<StockExternalDomain>> getStockExternalInfo(){
        return stockService.getStockExternalInfo();
    }

    /**
     * 查询沪深两市最新的板块行情数
     * @return
     */
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getSectorAll(){
        return stockService.getSectorAll();
    }

    /**
     * 涨幅榜更多数据
     */
    @GetMapping("/stock/all")
    public R<PageResult> getStockPageInfo(Integer page, Integer pageSize){
        return stockService.getStockPageInfo(page, pageSize);
    }
    /**
     * 涨幅榜
     */
    @GetMapping("/stock/increase")
    public R<List<StockTopDomain>> getStockIncrease(){
        return stockService.getStockIncrease();
    }

    /**
     * 涨跌停数据统计
     */
    @GetMapping("/stock/updown/count")
    public R<Map<String, List>> getStockUpdownCount(){
        return stockService.getStockUpdownCount();
    }

    /**
     * 导出指定页码的最新股票信息
     */
    @GetMapping("/stock/export")
    public void getStockExport(HttpServletResponse response, Integer page, Integer pageSize){
        stockService.getStockExport(response,page,pageSize);
    }

    /**
     * 股票成交量对比功能
     */
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List>> getStockTradeAmt(){
        return stockService.getStockTradeAmt();
    }

    /**
     * 统计最新交易时间点下股票在各个涨幅区间的数量
     */
    @GetMapping("stock/updown")
    public R<Map> getIncreaseRangeInfo(){
        return stockService.getIncreaseRangeInfo();
    }

    /**
     * 指定股票T日每分钟的交易数据
     */
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockMinutesInfo(String code){
        return stockService.getStockMinutesInfo(code);
    }

    /**
     * 个股日K线
     * @param code 股票代码
     * @return
     */
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockDayKInfo(String code){
        return stockService.getStockDayKInfo(code);
    }

    /**
     * TODO 个股周K线
     * @param code 股票代码
     */
    @GetMapping("/stock/screen/weekkline")
    public R<List<Stock4EvrWeekDomain>> getStockWeekKInfo(String code){
        return stockService.getStockWeekKInfo(code);
    }



    /**
     * 股票Code联想推荐
     * @param searchStr 股票代码
     * @return
     */
    @GetMapping("/stock/search")
    public R<List<Map<String,String>>> getStockSearch(String searchStr){
        return stockService.getStockByCode(searchStr);
    }

    /**
     * 个股主营业务查询
     * @param code 股票编码
     */
    @GetMapping("/stock/describe")
    public R<StockDescribeDomain> getStockDescribe(String code){
        return stockService.getStockDescribe(code);
    }

    /**
     * 个股最新分时行情数据
     * @param code
     * @return
     */
    @GetMapping("/stock/screen/second/detail")
    public R<StockRtDetailDomain> getStockRtDetail(String code){
        return stockService.getStockRtDetail(code);
    }

    /**
     * 个股实时交易流水查询
     */
    @GetMapping("/stock/screen/second")
    public R<List<StockRtScreenDomain>> getStockRtScreenInfo(String code){
        return stockService.getStockRtScreenInfo(code);
    }

}
